package com.zhao.lazy;

/**
 * 懒汉式（线程同步 安全）
 * 优点：懒加载。线程不安全。
 * 缺点：效率低。
 */
public class LazyThreadSafe {
    //1.私有化构造方法
    private LazyThreadSafe() {

    }
    //2.声明静态变量
    private static LazyThreadSafe lazyThreadSafe;
    //3.提供获取实例的接口
    public static synchronized LazyThreadSafe getInstance() {
        if (lazyThreadSafe == null) {
            lazyThreadSafe = new LazyThreadSafe();
        }
        return lazyThreadSafe;
    }
}